(define TEST-NUM 1000000000)
(define (timed-prime-test n)
    (newline)
    (display n)
    (start-prime-test n (runtime)))

(define (start-prime-test n start-time)
    (if (prime? n)
        (report-prime (- (runtime) start-time))))

(define (report-prime elapsed-time)
    (display " *** ")
    (display elapsed-time))

(define (prime? n)
    (define (smallest-divisor n)
        (define (find-divisor n test-divisor)
            (define (divides? a b)
                (= (remainder b a) 0))
            (cond   ((> (square test-divisor) n) n)
                    ((divides? test-divisor n) test-divisor)
                    (else (find-divisor n (+ test-divisor 1)))))
        (find-divisor n 2))
    (= n (smallest-divisor n)))

; timed-prime-test get result in seconds, use ticks instead
; (define (search-for-primes start-num)
;     (if (prime? start-num)
;         (timed-prime-test start-num)
;         (search-for-primes (+ start-num 1))))

(define (next-odd n)
    (if (odd? n)
        (+ n 2)
        (+ n 1)))

(define (continue-primes n count)
    (cond   ((= count 0)
                (display "are primes."))
            ((prime? n)
                (display n)
                (newline)
                (continue-primes (next-odd n) (- count 1)))
            (else
                (continue-primes (next-odd n) count))))

(define (search-for-primes n)
    (let ((start-time (real-time-clock)))
        (continue-primes n 10)
        (display "\nconsumed time: ")
        (display (- (real-time-clock) start-time))
        (display " ms")))

(display "\n========================================\n")
; (timed-prime-test 1000000007)
; (search-for-primes 1000000000000)
; (display (prime? 1000000007))
; (display (next-odd 11))
; (continue-primes 1000 3)
(search-for-primes TEST-NUM)
(display "\n========================================\n")
